/**
 * SystemPreferences.h
 */
#ifndef SYSTEMPREFERENCES_H_
#define SYSTEMPREFERENCES_H_

#include <string>

#include <fstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>

/**
 * Represents the system preferences,
 * including screen resolution and depth color
 */
class SystemPreferences {
public:
  /**
   * Constructor
   */
  SystemPreferences();

  /**
   * Factory that create an instance from a configuration file
   * @param file the file where config is loaded
   */
  static SystemPreferences* SystemPreferencesFactory(std::string file);

  /**
   * Constructor for a full specification
   */
  SystemPreferences(int xRes, int yRes, int depthColor, int velocity,
      float backTranslate, float lateralBackTranslate, float lateralDelta,
      float lateralRotate);
  /**
   * Destructor
   */
  virtual ~SystemPreferences();

  /**
   * Set the screen resolution
   * @param width the width of the screen in pixels
   * @param height the height of the screen in pixels
   * @param depth set the color depth in bits
   */
  void setScreenResolution(int width, int height, int depth);

  /**
   * Return the screen resolution
   * @param width the width in pixels
   * @param height the height in pixels
   * @param depth the color depth in bits
   */
  void getScreenResolution(int& width, int& height, int& depth);

  /**
   * Set the function that defines the relation between percentage of
   * the transition and the real place of the application
   * @param t the current time (between 0 and 1)
   * @return the transition state (between 0 and 1)
   */
  float transition(float t);

  /**
   * Save the system configuration to a file
   * @param file the file target where the config is saved
   */
  void saveConfiguration(std::string file);

  /** getters */
  /**
   * Get the X res of the screen
   * @return the X res in pixels
   */
  int getXRes();
  
  /**
   * Get the Y res of the screen
   * @return the Y res in pixels
   */
  int getYRes();
  
  /**
   * Get the color depth
   * @return the color depth in bits
   */
  int getDepthColor();
  
  /**
   * Get the velocity of the animation
   * @return the velocity in ms 
   */
  int getVelocity();

  /**
   * Get the back translation of the central app
   * @return the back translate of central app
   */
  float getBackTranslate();

  /**
   * Get the lateral back translate
   * @return the lateral back translation
   */
  float getLateralBackTranslate();

  /**
   * Get the lateral space between central app and lateral app
   * @return the lateral delta
   */
  float getLateralDelta();

  /**
   * Get the rotation of lateral applications
   * @return the rotation of lateral application in degrees
   */
  float getLateralRotate();

private:
  friend class boost::serialization::access;
  template<class Archive>
  /**
   * Saves the preference or load preferences to / from an archive
   */
  void serialize(Archive & ar, const unsigned int version);

  /**
   * Height of the screen resolution
   */
  int _xRes;

  /**
   * Width of the screen resolution
   */
  int _yRes;

  /**
   * Depth Color of the screen resolution
   */
  int _depthColor;

  /**
   * Velocity of transitions between rotations
   */
  int _velocity;

  /**
   * Back translation of the front application
   */
  float _backTranslate;

  /**
   * Lateral back translation of a background application
   */
  float _lateralBackTranslate;

  /**
   * Translation between central and lateral ones
   */
  float _lateralDelta;

  /**
   * Rotation from front to lateral application
   */
  float _lateralRotate;
};

#endif /* SYSTEMPREFERENCES_H_ */
